package com.yylending.las.common.utils;

import android.os.CountDownTimer;
import android.widget.TextView;

/**
 * Created by Pengrf on 2016/11/1 11:43.
 *计时器工具类
 */
public class CountDownTimerUtils extends CountDownTimer {
    private TextView mTextView;
    //获取验证码按钮文字
    private String mBtnText = "";
    //倒计时提示文字
    private String mSecondHint = "";

    public CountDownTimerUtils(TextView textView, long millisInFuture, long countDownInterval, String text, String secondHint) {
        super(millisInFuture, countDownInterval);
        this.mTextView = textView;
        this.mBtnText = text;
        this.mSecondHint = secondHint;
    }

    @Override
    public void onTick(long millisUntilFinished) {
        //设置不可点击
        //mTextView.setClickable(false);
        mTextView.setEnabled(false);
        //设置倒计时间
        mTextView.setText(String.format(mSecondHint, millisUntilFinished / 1000));
    }

    @Override
    public void onFinish() {
        mTextView.setText(mBtnText);
        mTextView.setEnabled(true);
    }
}
